<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib prefix="his_fns" uri="/WEB-INF/tlds/his_fns.tld" %>

<c:forEach items="${stock}" var="s">
    <tr id="'${s.id}'" ondblclick="addBloodMatchTable('${s.id}',this)">
        <td>${s.bloodInpMaster.inpNo}<input name="flag" id="flag" type="hidden" value="0"></td>
        <td hidden>${s.id}</td>
        <td>${s.bloodId}</td>
        <td>${his_fns:getBloodComponentName(s.componentId)}</td>
        <td>${fns:getDictLabel(s.patBloodGroup,'BLOOD_TYPE_DICT' ,'' )}</td>
        <td>${s.bloodCapacity}</td>
        <td>${fns:getDictLabel(s.units,'BLOOD_UNIT_DICT' ,'' )}</td>
    </tr>
</c:forEach>
<script type="text/javascript">
    function addBloodMatchTable(id,obj){
        var flag = $(obj).children().find("input").val();
        if(flag=='0'){
            $(obj).children().find("input").val("1");
            $.ajax({
                url: '${ctx}/blood/bloodMatch/getInpDetailById?id=' + id,
                type: 'get',
                contentType: 'application/json',
                async: true,
                success: function (data, textStatus, jqXHR) {
                    var applyId = $('#applyTable .table-selected').find('td:eq(0)').text(); //获取选中申请单号
                    var tbIdx = 0;
                    if (typeof($("#contentTable tbody tr:last").attr('xia')) == 'undefined') {
                        tbIdx = 0;
                    } else {
                        tbIdx = Number($("#contentTable tbody tr:last").attr('xia')) + 1;
                    }
                    var trHTML = "<tr xia='" + tbIdx + "'>";
                    trHTML += "<td hidden>" + data.id + "<input type='hidden' id='matchList[" + tbIdx + "].id' name='matchList[" + tbIdx + "].id' value='" + data.id + "'" + "/></td>";
                    trHTML += "<td hidden>" + applyId + "<input type='hidden' id='matchList[" + tbIdx + "].applyId' name='matchList[" + tbIdx + "].applyId' value='" + applyId + "'" + "/></td>";
                    trHTML += "<td>" + data.bloodId + "<input type='hidden' id='matchList[" + tbIdx + "].bloodId' name='matchList[" + tbIdx + "].bloodId' value='" + data.bloodId + "'" + "/></td>";
                    trHTML += "<td>" + data.patBloodGroupName + "<input type='hidden' id='matchList[" + tbIdx + "].patBloodGroupName' name='matchList[" + tbIdx + "].patBloodGroupName' value='" +
                    data.patBloodGroupName + "'" + "/></td>";
                    trHTML += "<td hidden>" + data.componentId + "<input type='hidden' id='matchList[" + tbIdx + "].componentId' name='matchList[" + tbIdx + "].componentId' value='" + data.componentId + "'" + "/></td>";
                    trHTML += "<td>" + data.componentName + "<input type='hidden' id='matchList[" + tbIdx + "].componentName' name='matchList[" + tbIdx + "].componentName' value='" + data.componentName +
                    "'" + "/></td>";
                    trHTML += "<td>" + data.invalDate + "<input type='hidden' id='matchList[" + tbIdx + "].invalDate' name='matchList[" + tbIdx + "].invalDate' value='" + data.invalDate + "'" +
                    "/></td>";
                    trHTML += "<td><select class='form-control' name='matchList[" + tbIdx + "].matchMetch'>";
                    if (data['matchMetchDictList'].length > 0) {
                        for (var i = 0; i < data['matchMetchDictList'].length; i++) {
                            trHTML += "<option value='" + data['matchMetchDictList'][i].value + "'>" + data['matchMetchDictList'][i].label + "</option>"
                        }
                    } else {
                        trHTML += "<option value=''></option>";
                    }
                    trHTML += "</select></td>";
                    trHTML += "<td><select class='form-control' name='matchList[" + tbIdx + "].matchResult'>";
                    if (data['matchResultDictList'].length > 0) {
                        for (var i = 0; i < data['matchResultDictList'].length; i++) {
                            trHTML += "<option value='" + data['matchResultDictList'][i].value + "'>" + data['matchResultDictList'][i].label + "</option>"
                        }
                    } else {
                        trHTML += "<option value=''></option>";
                    }
                    trHTML += "</select></td>";
                    trHTML += "<td><select class='form-control' name='matchList[" + tbIdx + "].bloodUser1'>";
                    if (null != data['matchUserList'] && typeof(data['matchUserList']) != 'undefined' && data['matchUserList'] != [] && data['matchUserList'].length > 0) {
                        for (var i = 0; i < data['matchUserList'].length; i++) {
                            trHTML += "<option value='" + data['matchUserList'][i].id + "'>" + data['matchUserList'][i].name + "</option>"
                        }
                    } else {
                        trHTML += "<option value=''></option>";
                    }
                    trHTML += "</select></td>";
                    trHTML += "<td><select class='form-control' name='matchList[" + tbIdx + "].matchResultSecond'>";
                    if (null != data['matchResultDictList'] && typeof(data['matchResultDictList']) != 'undefined' && data['matchResultDictList'] != [] && data['matchResultDictList'].length > 0) {
                        for (var i = 0; i < data['matchResultDictList'].length; i++) {
                            trHTML += "<option value='" + data['matchResultDictList'][i].value + "'>" + data['matchResultDictList'][i].label + "</option>"
                        }
                    } else {
                        trHTML += "<option value=''></option>";
                    }
                    trHTML += "</select></td>";
                    trHTML += "<td><select class='form-control' name='matchList[" + tbIdx + "].bloodUser2'>";
                    if (null != data['matchUserList'] && typeof(data['matchUserList']) != 'undefined' && data['matchUserList'] != [] && data['matchUserList'].length > 0) {
                        for (var i = 0; i < data['matchUserList'].length; i++) {
                            trHTML += "<option value='" + data['matchUserList'][i].id + "'>" + data['matchUserList'][i].name + "</option>"
                        }
                    } else {
                        trHTML += "<option value=''></option>";
                    }
                    trHTML += "</select></td>";
                    trHTML += "</tr>";
                    $("#contentTable").append(trHTML);
                }
            });
        }else{
            toastr.error("该血袋已在配血区配血,请选择其他血袋!");
        }
    }
</script>